package ar.edu.uba.fi.jmit.integrationtest;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.integrationtest.averagemethodtime.AverageMethodTimeTest;
import ar.edu.uba.fi.jmit.integrationtest.fieldvalue.FieldValueTest;
import ar.edu.uba.fi.jmit.integrationtest.invocationcountermethod.InvocationCounterMethodTest;
import ar.edu.uba.fi.jmit.integrationtest.manymonitorsdifferentsenviroments.ManyMonitorsDifferentsEnviromentsTest;
import ar.edu.uba.fi.jmit.integrationtest.methodtime.MethodTimeTest;
import ar.edu.uba.fi.jmit.integrationtest.objectcount.ObjectCountTest;

/**
 * Clase que ejecuta todos los tests de integracion
 * @author Tomas
 *
 */
public class IntegrationTestMain {
	
	private static IntegrationTest[] tests = new IntegrationTest[]{new MethodTimeTest(), 
		new AverageMethodTimeTest(), new ObjectCountTest(), new InvocationCounterMethodTest(), 
		new FieldValueTest(), new ManyMonitorsDifferentsEnviromentsTest()};
	
	private static long testTime = 3600000;
	
	private static Logger logger = Logger.getLogger("main");

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		addShutDownHooks();
		logger.info("Starting tests...");
		startTests();
		logger.info("All tests started, will wait " + testTime + "ms");
		Thread.sleep(testTime);
		logger.info("Test time finished, stopping...");
		stopThreads();
	}

	private static void stopThreads() {
		for(IntegrationTest test:tests) {
			test.stop();
		}
		
	}

	private static void startTests() {
		for(IntegrationTest test:tests) {
			test.start();
		}
		
	}

	private static void addShutDownHooks() {
		for(IntegrationTest test:tests) {
			Runtime.getRuntime().addShutdownHook(new IntegrationTestShutDownHook(test));
		}
	}
}
